<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__UI__/css/bs3/dpl.css" rel="stylesheet">
<link href="__UI__/css/bs3/bui.css" rel="stylesheet">
<link href="__UI__/css/page.css" rel="stylesheet" type="text/css" />
</head>
<body> 
<div class="container">
	<div class="row">
		<!--<form id="searchForm" class="form-horizontal span24">
			<div class="row">
				<div class="control-group span8">
					<label class="control-label">搜索类型：</label>
					<div class="controls">
						<select id="" name="mark">
                        	<option value="nickname">用户昵称</option>
							<option value="username">用户名称</option>
                            <option value="company">公司名称</option>
						</select>
					</div>
				</div>
                <div class="control-group span8">
					<label class="control-label">搜索内容：</label>
					<div class="controls">
						<input type="text" class="control-text" name="search" data-tip="{text:'请输入搜索内容'}">
					</div>
				</div>
                <div class="span3 offset1">
					<button  type="button" id="btnSearch" class="button button-primary">搜索</button>
				</div>
			</div>
		</form>-->
	</div>
	<div class="search-grid-container">
		<div id="grid"></div>
	</div>
</div>
<script type="text/javascript" src="__UI__/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="__UI__/js/bui.js"></script>
<script type="text/javascript" src="__UI__/js/config.js"></script>
<script type="text/javascript">
	top.topManager.closePage('member_add');
	top.topManager.closePage('member_edit');
	top.topManager.closePage('member_repwd');
	BUI.use('common/page');
	BUI.use(['common/search','bui/overlay'],function (Search,Overlay){
		var columns = [
			{title:'用户昵称',dataIndex:'nickname',width:200},
			{title:'用户名称',dataIndex:'username',width:100},
			{title:'公司名称',dataIndex:'company',width:200},
			{title:'创建时间',dataIndex:'create_time',width:100},
			{title:'更新时间',dataIndex:'update_time',width:100},
			{title:'上次登录时间',dataIndex:'last_login_time',width:150},
			{title:'上次登录IP',dataIndex:'last_login_ip',width:150},
			{title:'数据操作',dataIndex:'',width:80,renderer:function(value,obj){
				var pwdStr = Search.createLink({
					id:'member_repwd' + obj.id,
					title:'用户密码',
					text:'密码',
					href:'{:U("Member/repwd/id/' + obj.id + '")}',
					isClose:true,
				}),editStr = Search.createLink({
					id:'member_edit' + obj.id,
					title:'用户编辑',
					text:'编辑',
					href:'{:U("Member/edit/id/' + obj.id + '")}',
					isClose:true,
				}),
				delStr = '<span class="grid-command btn-del" title="用户删除">删除</span>';
				Search.createLink;
				return pwdStr;
			}}
		],
		store = Search.createStore('{:U("Member/index")}',{
			proxy:{
				save:{removeUrl:'{:U("Member/index")}'}
			},
			autoSync:true,
			pageSize:10,
			
		}),
		gridCfg = Search.createGridCfg(columns,{
			forceFit:true,
			tbar:{
				items:[
					{text : '<i class="icon-refresh"></i>刷新页面',btnCls : 'button button-small',handler:function(){
						window.location.reload();
					}},
					/*{text : '<i class="icon-plus"></i>用户新建',btnCls : 'button button-small',handler:function(){
						top.topManager.openPage({
							id:'member_add',
							title:'用户新建',
							href:'{:U("Member/add")}',
							isClose:true,
						});
					}},
					{text:'<i class="icon-remove"></i>批量删除',btnCls:'button button-small',handler:delFunction},*/
				]
			},
			plugins:[BUI.Grid.Plugins.CheckSelection,BUI.Grid.Plugins.RowNumber] 
		});
		var  search = new Search({
			store:store,
			gridCfg:gridCfg,
		}),
		grid = search.get('grid');
		function delFunction(){
			var selections = grid.getSelection();
			delItems(selections);
		}
		function delItems(items){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				BUI.Message.Confirm('确认要删除选中的记录么？',function(){
					$.ajax({
						url:'{:U("Member/del")}',
						dataType:'json',
						data:{ids : ids},
						success:function(data){
							if(data.status == 'y'){
								search.load();
							}else{
								BUI.Message.Alert('删除失败！');
							}
						}
					});
				},'question');
			}
		}
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-del')){
				var record = ev.record;
				delItems([record]);
			}
		});
		function auditFunction(){
			var selections = grid.getSelection();
			auditItems(selections);
		}
		function auditItems(items){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				BUI.Message.Confirm('确认更改状态',function(){
					$.ajax({
						url:'{:U("Member/audit")}',
						dataType:'json',
						data:{ids : ids},
						success:function(data){
							if(data.status == 'y'){
								//BUI.Message.Alert('开启状态成功！');
								search.load();
							}else{
								BUI.Message.Alert('更改失败！');
							}
						}
					});
				},'question');
			}
		}
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-audit')){
				var record = ev.record;
				auditItems([record]);
			}
		});
	});
</script>
</body>
</html>